using System;
using UnityEngine;
using UnityEngine.UI;

public class BounceValue : MonoBehaviour
{
    public Slider slider;
    public Text sliderValue;
    public Text height;
    
    public BounceBallDrop ball;
        
    // Start is called before the first frame update

    void Start()
    {
        slider.value = 0.7f;
        OnSliderValueChanged(slider.value);
        
        slider.onValueChanged.AddListener(OnSliderValueChanged);
    }

    private void OnSliderValueChanged(float value)
    {
        ball.attenuation = value * (BounceBallDrop.BOUNCE_MAX - BounceBallDrop.BOUNCE_MIN) + BounceBallDrop.BOUNCE_MIN;
        sliderValue.text = ball.attenuation.ToString("F2");
    }

    private void Update()
    {
        float fHeight = Mathf.Max(0, ball.transform.position.y);
        height.text = fHeight.ToString("F3");
    }
}
